from flask import Flask
from flask_sqlalchemy import SQLAlchemy
from config import config
from flask_session import Session
from info.modules.news import views
import logging
from logging.handlers import RotatingFileHandler

logging.basicConfig(level=logging.DEBUG)
file_log_handle = RotatingFileHandler("logs/log", maxBytes=1024 * 1024 * 100, backupCount=10)
formatter = logging.Formatter("%(levelname)s %(filename)s:%(lineno)s %(message)s")
file_log_handle.setFormatter(formatter)
logging.getLogger().addHandler(file_log_handle)


def create_app(env):
    app = Flask(__name__)

    app.config.from_object(config[env])

    db = SQLAlchemy(app)

    app.register_blueprint(views.news)

    Session(app)
    return app
